﻿<%@ WebHandler Language="C#" Class="detail" %>
using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.Collections;

public class detail : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        string openid = context.Request.Headers["X-ACCESS-USER"];//Header中的token
        if (string.IsNullOrEmpty(openid))
        {
            HttpContext.Current.Response.Write("parameter error");
            return;
        }
        var code = 1;
        var msg = "用户信息";
        var time = DateTime.Now;

        using (Entities bll = new Entities())
        {


            var studentSumScore_2 = bll.P_T_Sign.GroupBy(m => m.UserId).Select(k => new { UserId = k.Key, JF = k.Sum(l => l.JF) }).OrderByDescending(m => m.JF).ToList();




            ArrayList list = new ArrayList();


            foreach (var x in studentSumScore_2)
            {

                var user = bll.User.SingleOrDefault(p=>p.UOpenID==x.UserId);//全部.ToList();
                if (user != null)
                { 

                list.Add(new
                {
                    username = user.UNickName,
                    usehead = user.UHeadImg,
                    jb = user.Ujifen,
                    jf = x.JF,
                    x.UserId

                }) ;
                        }

            }

            context.Response.Write(JsonConvert.SerializeObject(new {code,msg,time,list}));

        }

        HttpContext.Current.Response.End();
        //context.Response.Write("Hello World");


    }





    public bool IsReusable {
        get {
            return false;
        }
    }

}